﻿using System;
using System.Text.RegularExpressions;

public static class StringExtension
{
    public static string ToSiretNumber(this string Siret)
    {
        string Result;
        try
        {
            Result = Regex.Replace(Siret, "(?<first>([0-9]{3}))(?<second>([0-9]{3}))(?<third>([0-9]{3}))(?<fourth>([0-9]{5}))",
                "${first} ${second} ${third} ${fourth}");
        }
        catch (ArgumentException)
        {
            Result = Siret;
        }
        return Result;
    }

    public static string ToFrenchPhoneNumber(this string PhoneNumber)
    {
        if (PhoneNumber.StartsWith("0"))
            return string.Format("+33 {0} {1} {2} {3} {4}", PhoneNumber.Substring(1, 1), PhoneNumber.Substring(2, 2), PhoneNumber.Substring(4, 2), PhoneNumber.Substring(6, 2), PhoneNumber.Substring(8, 2));
        else
            if (PhoneNumber.StartsWith("+"))
                return string.Format("{0} {1} {2} {3} {4} {4}", PhoneNumber.Substring(0, 3), PhoneNumber.Substring(3, 1), PhoneNumber.Substring(4, 2), PhoneNumber.Substring(6, 2), PhoneNumber.Substring(8, 2), PhoneNumber.Substring(10, 2));
            else
                return string.Format("+{0} {1} {2} {3} {4} {4}", PhoneNumber.Substring(0, 2), PhoneNumber.Substring(2, 1), PhoneNumber.Substring(3, 2), PhoneNumber.Substring(5, 2), PhoneNumber.Substring(7, 2), PhoneNumber.Substring(9, 2));
    }
}